package org.example.server;

import io.vertx.core.Vertx;

public class VertxHttpServer implements HttpServer{
    @Override
    public void doStart(int port) {
        System.out.println(Thread.currentThread().getName() + "执行VertxHttpServer的doStart方法()");
        //创建Vert.x实例
        Vertx vertx = Vertx.vertx();
        //创建HTTP服务器
        io.vertx.core.http.HttpServer httpServer = vertx.createHttpServer();
        //监听端口并处理请求
        httpServer.requestHandler(new HttpServerHandle());

        //启动HTTP服务器并监听指定端口
        httpServer.listen(port,result->{
            if (result.succeeded()){
                System.out.println("服务启动 Server is now listening on port" + port);
            }else {
                System.err.println("Failed to start server: " + result.cause());
            }
        });
    }
}
